package android.slc.main_biz.ui.main.curve;

import android.view.animation.Interpolator;

import androidx.interpolator.view.animation.FastOutSlowInInterpolator;

import java.util.Random;

public class FastOutSlowInCurve {

    public final static Interpolator fastOutSlowInInterpolator = new FastOutSlowInInterpolator();
    private final Random random = new Random();
    //曲线
    private float curveValue;
    //曲线增加步长
    private float stepValue;
    //正负极
    private boolean direction = true;
    //是否是增加模式
    private boolean addModel = true;

    public FastOutSlowInCurve() {
        reset();
    }

    public float getInterpolation() {
        float interpolation = fastOutSlowInInterpolator.getInterpolation(curveValue);
        if (interpolation == 0) {
            addModel = !addModel;
        } else if (interpolation == 1) {
            addModel = !addModel;
        }
        if (addModel) {
            curveValue += stepValue;
        } else {
            curveValue -= stepValue;
        }
        return interpolation - 0.5f;
    }

    public void reset() {
        curveValue = 0.5f+random.nextFloat()/2;
        stepValue = 0.004f + (0.006f - 0.004f) * random.nextFloat();
        addModel = true;
        direction = true;
    }
}